﻿using CheryABP.Common;
using CheryABP.Net.MimeTypes;
using System;

namespace CheryABP.VerifyCodes
{
    /// <summary>
    /// 验证码
    /// </summary>
    public class VerifyCodeAppService :IVerifyCodeAppService
    {
        /// <summary>
        /// 返回base64图片验证码
        /// </summary>
        /// <returns></returns>
        public GetVerifyCodeOutput GetVerifyCode()
        {
            string code = VerifyCodeHelper.GetSingleObj().CreateVerifyCode(VerifyCodeHelper.VerifyCodeType.NumberVerifyCode);
            byte[] bytes = VerifyCodeHelper.GetSingleObj().CreateByteByImgVerifyCode(code, 100, 40);
            var image = $"data:{MimeTypeNames.ImageJpeg};base64,{Convert.ToBase64String(bytes)}";
            var output = new GetVerifyCodeOutput()
            {
                Image = image,
                code = code
            };
            return output;
        }
    }
}
